<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="Content-Style-Type" content="text/css">
<title></title>
<meta name="Generator" content="Cocoa HTML Writer">
<meta name="CocoaVersion" content="824.41">
<style type="text/css">
p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Helvetica}
p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica; min-height: 14.0px}
p.p3 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica}
p.p4 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco}
p.p5 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; min-height: 12.0px}
p.p6 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #9d1c12}
p.p7 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #0026b4}
p.p8 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #9d1c12; min-height: 12.0px}
p.p9 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #3d6d1d}
span.s1 {font: 18.0px Helvetica}
span.s2 {color: #0026b4}
span.s3 {text-decoration: underline}
span.s4 {color: #000000}
span.s5 {color: #3d6d1d}
span.Apple-tab-span {white-space:pre}
</style>
</head>
<body>
<p class="p1"><span class="s1"><b>AY<span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span></b></span><b>Emulator of the AY (aka YM) soundchip, used in Spectrum/Atari</b></p>
<p class="p2"><br></p>
<p class="p3"><span class="Apple-tab-span">	</span><b>AY.ar(tonea, toneb, tonec, noise, control, vola, volb, volc, envfreq, envstyle, chiptype, mul, add)</b></p>
<p class="p2"><br></p>
<p class="p3">Emulates the General Instrument AY-3-8910 (a.k.a. the Yamaha YM2149) 3-voice sound chip, as found in the <b><i>ZX Spectrum 128</i></b>, the <b><i>Atari ST</i></b>, and various other home computers during the 1980s.</p>
<p class="p2"><br></p>
<p class="p3">The inputs are as follows:</p>
<p class="p2"><br></p>
<p class="p3"><b><span class="Apple-converted-space"> </span>* tonea, toneb, tonec</b> - integer "tone" value for each of the 3 voices, from <b><i>0 to 4095</i></b> (i.e. 12-bit range). Higher value = lower pitch. For convenience, the <span class="s2">AY</span>.freqtotone method converts a frequency value to something appropriate for these inputs.</p>
<p class="p3"><b><span class="Apple-converted-space"> </span>* noise</b> - the period of the pseudo-random noise generator, <b><i>0 to 31</i></b></p>
<p class="p3"><b><span class="Apple-converted-space"> </span>* control</b> - controls how the noise is mixed into the tone(s), <b><i>0 to 32</i></b> (0 is mute). This is a binary mask value which masks the noise/tone mixture in each channel, so it's not linear.</p>
<p class="p3"><b><span class="Apple-converted-space"> </span>* vola, volb, volc</b> - volume of the three channels, <b><i>0 to 15</i></b> (or 0 to 31 if using YM chiptype)</p>
<p class="p3"><b><span class="Apple-converted-space"> </span>* envfreq</b> - envelope frequency, <b><i>0 to 4095</i></b></p>
<p class="p3"><b><span class="Apple-converted-space"> </span>* envstyle</b> - type of envelope used, <b><i>0 to 15</i></b></p>
<p class="p3"><b><span class="Apple-converted-space"> </span>* chiptype</b> - <b><i>0</i></b> for AY (default), <b><i>1</i></b> for YM. The models behave slightly differently. This input cannot be modulated - its value is only handled at the moment the UGen starts.</p>
<p class="p3"><b><span class="Apple-converted-space"> </span>* mul, add</b> - general multiply/add controls for the resulting signal</p>
<p class="p2"><br></p>
<p class="p3">The chip's inputs are integer values, so non-integer values will be rounded off.</p>
<p class="p2"><br></p>
<p class="p3">The emulation is provided by the <i>libayemu</i> library: <span class="s3">http://sourceforge.net/projects/libayemu</span> - I have merely wrapped it up as a SC UGen.</p>
<p class="p2"><br></p>
<p class="p2"><br></p>
<p class="p3"><b>Examples</b></p>
<p class="p2"><br></p>
<p class="p4">s.boot;</p>
<p class="p5"><br></p>
<p class="p6">// Default...</p>
<p class="p4">x = {<span class="s2">AY</span>.ar * 0.1}.play(s);</p>
<p class="p4">x.free;</p>
<p class="p5"><br></p>
<p class="p6">// Mouse-controlled tones<span class="Apple-converted-space"> </span></p>
<p class="p4">(</p>
<p class="p4">x = {</p>
<p class="p4"><span class="Apple-tab-span">	</span><span class="s2">Pan2</span>.ar(<span class="s2">AY</span>.ar(</p>
<p class="p4"><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span>tonea: <span class="Apple-tab-span">	</span><span class="s2">MouseY</span>.kr(10, 3900, 1),</p>
<p class="p4"><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span>toneb: <span class="Apple-tab-span">	</span><span class="s2">MouseX</span>.kr(10, 3900, 1),</p>
<p class="p4"><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span>control: <span class="Apple-tab-span">	</span>3,</p>
<p class="p4"><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span>vola: <span class="Apple-tab-span">	</span>14,</p>
<p class="p4"><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span>volb: <span class="Apple-tab-span">	</span>14,</p>
<p class="p4"><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span>volc: <span class="Apple-tab-span">	</span>0,</p>
<p class="p4"><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span>mul: 0.1</p>
<p class="p4"><span class="Apple-tab-span">	</span>))</p>
<p class="p4">}.play;</p>
<p class="p4">)</p>
<p class="p5"><br></p>
<p class="p4">x.free;</p>
<p class="p5"><br></p>
<p class="p6">// A random walk in a ZX Spectrum</p>
<p class="p4">(</p>
<p class="p4">x = {</p>
<p class="p6"><span class="s4"><span class="Apple-tab-span">	</span></span><span class="s2">var</span><span class="s4"> rate = </span><span class="s2">MouseX</span><span class="s4">.kr(0.1, 10); </span>// You control your wandering speed</p>
<p class="p4"><span class="Apple-tab-span">	</span><span class="s2">Pan2</span>.ar(<span class="s2">AY</span>.ar(</p>
<p class="p4"><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span>tonea: <span class="Apple-tab-span">	</span><span class="s2">LFDNoise3</span>.kr(rate).range(10, 3900),</p>
<p class="p4"><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span>toneb: <span class="Apple-tab-span">	</span><span class="s2">LFDNoise3</span>.kr(rate).range(10, 3900),</p>
<p class="p4"><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span>tonec: <span class="Apple-tab-span">	</span><span class="s2">LFDNoise3</span>.kr(rate).range(10, 3900),</p>
<p class="p4"><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span>noise: <span class="Apple-tab-span">	</span><span class="s2">LFDNoise3</span>.kr(rate).range(0, 31),</p>
<p class="p4"><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span>control: <span class="Apple-tab-span">	</span><span class="s2">LFDNoise0</span>.kr(rate).range(0, 31),</p>
<p class="p4"><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span>vola: <span class="Apple-tab-span">	</span><span class="s2">LFDNoise3</span>.kr(rate).range(0, 15),</p>
<p class="p4"><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span>volb: <span class="Apple-tab-span">	</span><span class="s2">LFDNoise3</span>.kr(rate).range(0, 15),</p>
<p class="p4"><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span>volc: <span class="Apple-tab-span">	</span><span class="s2">LFDNoise3</span>.kr(rate).range(0, 15),</p>
<p class="p4"><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span>envfreq: <span class="Apple-tab-span">	</span><span class="s2">LFDNoise3</span>.kr(rate).range(0, 4095),</p>
<p class="p4"><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span>envstyle: <span class="Apple-tab-span">	</span><span class="s2">LFDNoise3</span>.kr(rate).range(0, 15),</p>
<p class="p4"><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span>mul: 0.1</p>
<p class="p4"><span class="Apple-tab-span">	</span>))</p>
<p class="p4">}.play;</p>
<p class="p4">)</p>
<p class="p5"><br></p>
<p class="p4">x.free;</p>
<p class="p5"><br></p>
<p class="p6">// Now to define a synth which can be used in patterns etc</p>
<p class="p4">(</p>
<p class="p7">SynthDef<span class="s4">(</span><span class="s5">\ay1</span><span class="s4">, { </span>| freqa=440, freqb=550, freqc=660, vola=15, volb=0, volc=0, chink=1, wobbly=1, pan=0, amp=0.1, gate=1|</p>
<p class="p4"><span class="Apple-tab-span">	</span><span class="s2">var</span> ay, chinkenv, wobblyenv;</p>
<p class="p5"><span class="Apple-tab-span">	</span></p>
<p class="p6"><span class="s4"><span class="Apple-tab-span">	</span></span>//chinkenv = if(chink&gt;0, EnvGen.kr(Env.new([0.06125, 0.06125, 1, 1], [0.05, 0, 0.1], 0, 4, 4)), 1);</p>
<p class="p4"><span class="Apple-tab-span">	</span>chinkenv = if(chink&gt;0, <span class="s2">EnvGen</span>.kr(<span class="s2">Env</span>.new([2, 2, 1, 1], [0.05, 0, 0.1], 0, 4, 4)), 1);</p>
<p class="p4"><span class="Apple-tab-span">	</span>wobblyenv = <span class="s2">LFPulse</span>.kr(10, 0.5, mul:wobbly).range(0.5, 1);</p>
<p class="p5"><span class="Apple-tab-span">	</span></p>
<p class="p4"><span class="Apple-tab-span">	</span># freqa, freqb, freqc = [freqa, freqb, freqc] * [1, wobblyenv, wobblyenv] * chinkenv;</p>
<p class="p4"><span class="Apple-tab-span">	</span>ay = <span class="s2">AY</span>.ar(<span class="s2">AY</span>.freqtotone(freqa), <span class="s2">AY</span>.freqtotone(freqb), <span class="s2">AY</span>.freqtotone(freqc),<span class="Apple-converted-space"> </span></p>
<p class="p4"><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span>0, 3, vola, volb, volc, mul: amp);</p>
<p class="p4"><span class="Apple-tab-span">	</span>ay = ay * <span class="s2">EnvGen</span>.kr(<span class="s2">Env</span>.asr(0.01, 1, 0.05), gate, doneAction:2);</p>
<p class="p4"><span class="Apple-tab-span">	</span><span class="s2">Out</span>.ar(0, <span class="s2">Pan2</span>.ar(ay, pan));</p>
<p class="p4">}).load(s);</p>
<p class="p4">)</p>
<p class="p5"><br></p>
<p class="p4">x = <span class="s2">Synth</span>(<span class="s5">\ay1</span>, [<span class="s5">\wobbly</span>, 0, <span class="s5">\chink</span>, 1, <span class="s5">\tonea</span>, 1000.rand]);</p>
<p class="p4">x.free;</p>
<p class="p5"><br></p>
<p class="p7">SynthDescLib<span class="s4">.read;</span></p>
<p class="p8"><br></p>
<p class="p6">// Use the synth in a jerky lo-fi pattern of some sort...</p>
<p class="p4">(</p>
<p class="p7">Pbind<span class="s4">(</span></p>
<p class="p9"><span class="s4"><span class="Apple-tab-span">	</span></span>\instrument<span class="s4">, </span>\ay1<span class="s4">,</span></p>
<p class="p4"><span class="Apple-tab-span">	</span><span class="s5">\freqa</span>,<span class="Apple-tab-span">	</span><span class="s2">Pseq</span>((#[55, 55, 57, 58, 57, 55, 58, 50]-12).midicps, <span class="s2">inf</span>),</p>
<p class="p9"><span class="s4"><span class="Apple-tab-span">	</span></span>\freqb<span class="s4">,<span class="Apple-tab-span">	</span></span><span class="s2">Pseq</span><span class="s4">([</span></p>
<p class="p4"><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span><span class="s2">Pseq</span>( (#[55, 55, 54, 55, 54, 55, 58, 57]+12).midicps, 2),</p>
<p class="p4"><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span><span class="s2">Prand</span>((#[55, 55, 54, 55, 54, 55, 58, 57]+12).midicps, 2)</p>
<p class="p4"><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span>], <span class="s2">inf</span>),</p>
<p class="p4"><span class="Apple-tab-span">	</span><span class="s5">\dur</span>,<span class="Apple-tab-span">	</span><span class="s2">Pseq</span>(#[3, 0.5, 0.5, 1.5, 0.5, 1, 1, 4] * 0.4, <span class="s2">inf</span>),</p>
<p class="p4"><span class="Apple-tab-span">	</span><span class="s5">\wobbly</span>,<span class="Apple-tab-span">	</span><span class="s2">Pstutter</span>(8 * 4, <span class="s2">Prand</span>(#[0, 1], <span class="s2">inf</span>)),</p>
<p class="p4"><span class="Apple-tab-span">	</span><span class="s5">\vola</span>,<span class="Apple-tab-span">	</span>15,</p>
<p class="p4"><span class="Apple-tab-span">	</span><span class="s5">\volb</span>,<span class="Apple-tab-span">	</span>14,</p>
<p class="p9"><span class="s4"><span class="Apple-tab-span">	</span></span>\chink<span class="s4">,<span class="Apple-tab-span">	</span>1,</span></p>
<p class="p4"><span class="Apple-tab-span">	</span><span class="s5">\amp</span>,<span class="Apple-tab-span">	</span>0.4</p>
<p class="p4">).play</p>
<p class="p4">)</p>
</body>
</html>
